<?php
/*
 * Camelot PHP Tools
 * This example illustrates how to download a List Item Attachement
 *
 * @version 2.0
 * @author Bendsoft
 * @package PHP Tools
 * @subpackage Camelot
 * @license FreeBSD License (www.bendsoft.com/licensing/)
 *
 * Note! 
 * Set up settings.php before using this file
 */
error_reporting(E_COMPILE_ERROR);
ini_set('display_errors', '1');


// Load all required files for Camelot PHP Tools
require_once '../loader.php';
?>

<?php include 'base/head.php'; ?>

<h2>Example DELETE Command</h2>
<p class="comment">For the full select documentation please visit <a href="http://www.bendsoft.com/documentation/camelot-net-connector/latest/sql-statement-syntax/delete/">http://www.bendsoft.com/documentation/camelot-net-connector/latest/sql-statement-syntax/delete/</a></p>
<form method="post">
    <div class="query">
        <label>Simple INSERT</label> 
        <textarea name="delete1" style="width: 400px; height: 40px;">
<?php echo ((!isset($_POST['delete1'])) || !$_POST ) ? 
"DELETE FROM Tasks WHERE Title LIKE 'Task%'"
: $_POST['delete1'] ?>
        </textarea>
        <input type="submit" name="delete1_submit" value="Submit" />
        <p class="comment">Delete all tasks that begins with the Title 'Task'</p>
    </div>

</form>


<?php
if ($_POST) {

    // Stopwatch
    $time_pre = microtime(true);

    try {

        $sql = '';

        if (isset($_POST['delete1_submit'])) {
            $sql = $_POST['delete1'];
        } 

        // Build command
        $command = new SharePointNonQueryCommand();
        $command->connection_name = "SharePointConnection1";
        $command->sql = $sql;

        // Execute command
        $result = new SharePointQuery($command);
        
        // If some form of exception occured and SILENT_EXCEPTIONS is set to TRUE
        if (!$result->commandStatus) {
            echo "<p>Silent exceptions is ON, this error message is forced to appear in this example</p>";
            $message = $result->exception->message;
            echo "<h2>Exception: $message</h2>";
            pr($result);
        } else {
            echo "Sucessfully executed the DELETE";
        }
    } catch (CamelotException $exc) {
        echo "<h2>Exception: $exc->message</h2>";
        pr($exc);
    }

    // ...end stopwatch
    $time_post = microtime(true);
    $exec_time = $time_post - $time_pre;
    echo "<p class=\"comment\">Query executed and data transfered in $exec_time seconds</p>";
}
?>

<?php include 'base/foot.html'; ?>